﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Jzy.BLL.Project;
using System.Data;
using Jzy.Model.Project;
using Jzy.Core.Common.Web;
using System.Web.UI.HtmlControls;
using Jzy.Core.Common;
using Frame.Lib.Utilities;
using Frame.Lib.Common;
using Frame.Lib.Enums;
using Frame.Lib.Web;

public partial class Project_TabList : PageDetail
{
    private string _prjID;
    private string PrjID
    {
        get
        {
            if(_prjID == null)
                _prjID = StrUtil.DecryptUrl(Request.QueryString["PrjID"]);
            return _prjID;
        }
    }

    /// <summary>
    /// 判断是某一个用户的项目还是所有项目
    /// </summary>
    private int? UserID
    {
        get
        {
            if (string.IsNullOrEmpty(Request["UserID"]))
            {
                return null;
            }
            else
            {
                return int.Parse(Decrypt(Request["UserID"]));
            }
        }
    }

    //判断是否是归档项目或作废项目
    private int? Status
    {
        get
        {
            if (string.IsNullOrEmpty(Request["Status"]))
            {
                return null;
            }
            else
            {
                return int.Parse(Decrypt(Request["Status"]));
            }
        }
    }

    protected string TabIndex
    {
        get
        {
            if (Request["TabIndex"] == null)
            {
                return "0";
            }
            else
            {
                return Request["TabIndex"];
            }

        }
    }

    protected void drpPrj_SelectedIndexChanged(object sender, EventArgs e)
    {
        string url = "TabList.aspx?PrjID=" + Encrypt(drpPrj.SelectedValue) + "&TabIndex=" + TabIndex;
        if (UserID != null)
        {
            url += "&UserID=" + Encrypt(UserID);
        }
        if (Status != null)
        {
            url += "&Status=" + Encrypt(Status);
        }
        Response.Redirect(url, true);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        JSUtil.SetDivHeight("content", 70);
        CssFileManager.AddCssFile(CssFile.tab1);
        if (!IsPostBack)
        {
            ProjectBO prj = new ProjectBO();
            prj.BindPrj(drpPrj,Status, UserID);
            drpPrj.SelectedValue = PrjID;
            BindList();
        }

        string paras = "";
        if (UserID != null)
        {
            paras += "&UserID=" + Encrypt(UserID);
        }
        if (Status != null)
        {
            paras += "&Status=" + Encrypt(Status);
        }
        lnkBack.HRef = "List.aspx?PrjID=" + StrUtil.EncryptUrl(PrjID) + paras;
        lnkTask.HRef = "Task/List.aspx?PrjID=" + StrUtil.EncryptUrl(PrjID) + paras;
    }
    private void BindList()
    {
        List<EnumInfo> list = ConvertUtil.ConvertEnum(typeof(PrjTab));
       
        foreach (EnumInfo info in list)
        {
            PrjTab tab = (PrjTab)info.ID;
            string paras = "?PrjID=" + StrUtil.EncryptUrl(PrjID);
          
            switch (tab)
            {
                case PrjTab.详细信息:
                    info.Tag = "Detail.aspx" + paras;
                    break;                
                case PrjTab.所有督办:
                    info.Tag = "Oversee/List.aspx" + paras;
                    break;
                case PrjTab.所有进展:
                    info.Tag = "Schedule/List.aspx" + paras;
                    break;
                case PrjTab.所有缺陷:
                    info.Tag = "BugManage/PrjBugList.aspx" + paras;
                    break;
                case PrjTab.附件:
                    info.Tag = "Attach/List.aspx" + paras;
                    break;               
            }
        }

        rpt.DataSource = list;
        rpt.DataBind();

        EnumInfo firstTab = list.Where(t => t.ID == int.Parse(TabIndex)).First();
        string script = "setFocus(document.getElementById('lnk_" + firstTab.ID + "'),'" + firstTab.Tag + "');";
        JSUtil.ExcuteJS(script);
    }

   
}
